package Dxc;

public class Test01 implements Runnable {

    private int tk = 10;

    @Override
    public void run() {
        while (true) {
            if (tk <= 0) {
                break;
            }
            //模拟延时，避免CPU运行太快使得结果一样
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "拿到了第" + tk-- + "票");
        }
    }

    public static void main(String[] args) {
        Test01 test01 = new Test01();

        new Thread(test01, "小明").start();
        new Thread(test01, "小呆呆").start();
        new Thread(test01, "刚子").start();

    }
}
/*但是多个线程操作同一个资源的情况下，线程不安全，数据紊乱*/
